package com.woshua.qmui;

import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import com.qmuiteam.qmui.util.QMUIResHelper;
import com.qmuiteam.qmui.widget.QMUITabSegment;
import com.qmuiteam.qmui.widget.QMUITopBar;
import com.qmuiteam.qmui.widget.QMUIViewPager;
import com.rxjava.rxlife.RxLife;
import com.woshua.qmui.adapter.TabPagerAdapter;
import com.woshua.qmui.bean.InfoBean;

import rxhttp.wrapper.param.RxHttp;

public class MainActivity extends AppCompatActivity {

    private QMUITopBar tabTopBar;

    private QMUITabSegment tabSegment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        tabTopBar=findViewById(R.id.qmui_tool_bar);

        final ViewPager vpContent = findViewById(R.id.vp_content);

        tabTopBar.setTitle("首页");

        tabTopBar.addLeftImageButton(R.mipmap.button_back,R.id.goback).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        tabSegment=findViewById(R.id.tab_segment);

        tabSegment.addTab(new QMUITabSegment.Tab("日维度"));
        tabSegment.addTab(new QMUITabSegment.Tab("月维度"));

        int normalColor = QMUIResHelper.getAttrColor(this, R.attr.qmui_config_color_gray_6);

        int selectColor = QMUIResHelper.getAttrColor(this, R.attr.qmui_config_color_blue);

        tabSegment.setDefaultNormalColor(normalColor);
        tabSegment.setDefaultSelectedColor(selectColor);

        TabPagerAdapter pagerAdapter=new TabPagerAdapter(getSupportFragmentManager());
        vpContent.setAdapter(pagerAdapter);
        tabSegment.setupWithViewPager(vpContent,false);

        tabSegment.setIndicatorWidthAdjustContent(false);
        tabSegment.setTabTextSize(18);

        RxHttp.postForm("wxarticle/chapters/json")       //发送表单形式的post请求
            .asObject(InfoBean.class)
            .as(RxLife.asOnMain(this))      //在主线程回调，并在页面销毁，自动关闭请求
            .subscribe(s -> {
                //成功回调
                System.out.println("-->>"+s.getData().get(0).getName());
            }, throwable -> {
                //失败回调
            });
    }
}
